﻿<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:project="clr-namespace:Projecturo.ProjecturoClient.ViewModel.Project"
    xmlns:sec="clr-namespace:Projecturo.ProjecturoClient.Security"
    xmlns:model="clr-namespace:Projecturo.Model;assembly=Projecturo.Model">

    <Style BasedOn="{StaticResource {x:Type TextBox}}" TargetType="{x:Type TextBox}" x:Key="SearchTicketBox">
        <Setter Property="Width" Value="60"/>    
    </Style>
    
    <Style TargetType="{x:Type Button}" x:Key="ProjectLinkButton">
        <Setter Property="Foreground" Value="#FF91A3CF"/>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate>
                    <Border>
                        <TextBlock x:Name="ProjectLink" Text="{Binding Name}" Foreground="{TemplateBinding Foreground}"/>
                    </Border>
                    <ControlTemplate.Triggers>
                        <Trigger Property="IsMouseOver" Value="True">
                            <Setter TargetName="ProjectLink" Property="TextDecorations" Value="Underline"/>
                            <Setter TargetName="ProjectLink" Property="Cursor" Value="Hand"/>
                            <Setter TargetName="ProjectLink" Property="Foreground" Value="#FF1A2E5E"/>
                        </Trigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
    
    <DataTemplate DataType="{x:Type project:ProjectViewModel}" x:Key="ProjectTemplate">
        <StackPanel>
            <Button Command="{Binding OpenProjectCommand}" 
                    CommandParameter="{Binding Id}" 
                    Content="{Binding Name}" 
                    Style="{StaticResource ProjectLinkButton}" />
        </StackPanel>
    </DataTemplate>
    
    <DataTemplate x:Key="ProjectListTemplate">
        <DockPanel MinHeight="150" MinWidth="200">
            <ListBox ItemsSource="{Binding Projects}" 
                     BorderThickness="0" 
                     Margin="4"
                     ItemTemplate="{StaticResource ProjectTemplate}"/>
        </DockPanel>
    </DataTemplate>

    <DataTemplate x:Key="TicketClickableButton">
        <Button Command="{Binding OpenTicketCommand}" Content="{Binding Name}" Style="{StaticResource ProjectLinkButton}" />
    </DataTemplate>

    <DataTemplate x:Key="DashboardTicketStateStyle">
        <StackPanel Orientation="Horizontal" HorizontalAlignment="Stretch" >
            <Border BorderThickness="0" CornerRadius="3" Width="12" Height="12" Background="{Binding State.Color}"/>
            <TextBlock Text="{Binding State.Name}"/>
        </StackPanel>
    </DataTemplate>

    <DataTemplate x:Key="RecentlyChangedTicketListTemplate">
        <DockPanel MinHeight="150" MinWidth="200">
            <ListView ItemsSource="{Binding RecentlyChangedTickets}" BorderThickness="0" Margin="4">
                <ListView.View>
                    <GridView>
                        <GridViewColumn Header="Id" DisplayMemberBinding="{Binding Id}"/>
                        <GridViewColumn CellTemplate="{StaticResource TicketClickableButton}" Header="Name"/>
                        <GridViewColumn Header="Project" DisplayMemberBinding="{Binding Project.Name}"/>
                        <GridViewColumn Header="Version" DisplayMemberBinding="{Binding Version.Name}"/>
                        <GridViewColumn CellTemplate="{StaticResource DashboardTicketStateStyle}" Header="Status"/>
                        <GridViewColumn Header="Editor" DisplayMemberBinding="{Binding AssignedTo.ShortName}"/>
                        <GridViewColumn Header="Reporter" DisplayMemberBinding="{Binding CreatedBy.ShortName}"/>
                        <GridViewColumn Header="Last Change" DisplayMemberBinding="{Binding Path=ChangeDate,StringFormat={}{0:d}}"/>
                    </GridView>
                </ListView.View>
            </ListView>
        </DockPanel>
    </DataTemplate>
    
    <DataTemplate x:Key="MyOpenTicketListTemplate">
        <DockPanel MinHeight="150" MinWidth="200">
            <ListView ItemsSource="{Binding MyOpenTickets}" BorderThickness="0" Margin="4">
                <ListView.View>
                    <GridView>
                        <GridViewColumn Header="Id" DisplayMemberBinding="{Binding Id}"/>
                        <GridViewColumn CellTemplate="{StaticResource TicketClickableButton}" Header="Name"/>
                        <GridViewColumn Header="Version" DisplayMemberBinding="{Binding Version.Name}"/>
                        <GridViewColumn Header="Project" DisplayMemberBinding="{Binding Project.Name}"/>
                        <GridViewColumn CellTemplate="{StaticResource DashboardTicketStateStyle}" Header="Status"/>
                        <GridViewColumn Header="Editor" DisplayMemberBinding="{Binding AssignedTo.ShortName}"/>
                        <GridViewColumn Header="Reporter" DisplayMemberBinding="{Binding CreatedBy.ShortName}"/>
                        <GridViewColumn Header="Last Change" DisplayMemberBinding="{Binding Path=ChangeDate,StringFormat={}{0:d}}"/>
                    </GridView>
                </ListView.View>
            </ListView>
        </DockPanel>
    </DataTemplate>
    
    <DataTemplate x:Key="ReportedByMeTicketListTemplate">
        <DockPanel MinHeight="150" MinWidth="200">
            <ListView ItemsSource="{Binding ReportedByMeTickets}" BorderThickness="0" Margin="4">
                <ListView.View>
                    <GridView>
                        <GridViewColumn Header="Id" DisplayMemberBinding="{Binding Id}"/>
                        <GridViewColumn CellTemplate="{StaticResource TicketClickableButton}" Header="Name"/>
                        <GridViewColumn Header="Version" DisplayMemberBinding="{Binding Version.Name}"/>
                        <GridViewColumn Header="Project" DisplayMemberBinding="{Binding Project.Name}"/>
                        <GridViewColumn CellTemplate="{StaticResource DashboardTicketStateStyle}" Header="Status"/>
                        <GridViewColumn Header="Editor" DisplayMemberBinding="{Binding AssignedTo.ShortName}"/>
                        <GridViewColumn Header="Reporter" DisplayMemberBinding="{Binding CreatedBy.ShortName}"/>
                        <GridViewColumn Header="Last Change" DisplayMemberBinding="{Binding Path=ChangeDate,StringFormat={}{0:d}}"/>
                    </GridView>
                </ListView.View>
            </ListView>
        </DockPanel>
    </DataTemplate>
    
    <DataTemplate x:Key="NewTicketListTemplate">
        <DockPanel MinHeight="150" MinWidth="200">
            <ListView ItemsSource="{Binding NewTickets}" BorderThickness="0" Margin="4">
                <ListView.View>
                    <GridView>
                        <GridViewColumn Header="Id" DisplayMemberBinding="{Binding Id}"/>
                        <GridViewColumn CellTemplate="{StaticResource TicketClickableButton}" Header="Name"/>
                        <GridViewColumn Header="Version" DisplayMemberBinding="{Binding Version.Name}"/>
                        <GridViewColumn Header="Project" DisplayMemberBinding="{Binding Project.Name}"/>
                        <GridViewColumn CellTemplate="{StaticResource DashboardTicketStateStyle}" Header="Status"/>
                        <GridViewColumn Header="Editor" DisplayMemberBinding="{Binding AssignedTo.ShortName}"/>
                        <GridViewColumn Header="Reporter" DisplayMemberBinding="{Binding CreatedBy.ShortName}"/>
                        <GridViewColumn Header="Last Change" DisplayMemberBinding="{Binding Path=ChangeDate,StringFormat={}{0:d}}"/>
                    </GridView>
                </ListView.View>
            </ListView>
        </DockPanel>
    </DataTemplate>
    
    <DataTemplate x:Key="CommandTemplate">
        <StackPanel Orientation="Horizontal">
            <Button Command="{Binding NewProjectCommand}" Content="New Project" Visibility="{x:Static sec:SecurityDescriptor.IsAdminVisibility}" />
            <Separator/>
            <Button Command="{Binding UserProfileCommand}" Content="User Profile"/>
            <Button Command="{Binding UserManagementCommand}" Content="User Management" Visibility="{x:Static sec:SecurityDescriptor.IsAdminVisibility}"/>
        </StackPanel>
    </DataTemplate>
    
</ResourceDictionary>